package com.itheima.leetcode.od.c.backtracking;

import java.util.HashMap;
import java.util.Scanner;

/**
 * <h3>全排列 / 排列个数</h3>
 * <h4>全排列无重复</h4>
 */
public class Permute {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        System.out.println(getResult(s));
    }

    public static int getResult(String s) {
        int total = getFact(s.length());

        HashMap<Character, Integer> count = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char k = s.charAt(i);
            count.put(k, count.getOrDefault(k, 0) + 1);
        }

        for (Character k : count.keySet()) {
            int n = count.get(k);
            if (n > 1) {
                total /= getFact(n);
            }
        }

        return total;
    }

    public static int getFact(int n) {
        int fact = 1;
        for (int i = 1; i <= n; i++) {
            fact *= i;
        }
        return fact;
    }
}